require('../css/register.less')

require('../font/iconfont.css')
const axios = require('../lib/axios/axios.js')


document.ready(function () {





    let reg = document.querySelector('#reg-ac');

    reg.addEventListener('click', function () {

        location.href = "./login.html"

    })



    let account = document.querySelector("#account");
    let password = document.querySelector("#l-paasord");
    let goTo = document.querySelector("#goto");

    // 登录
    goTo.addEventListener('click', () => {

        let v = account.value
        let p = password.value


        if (!($isPhone(v) && $isPassword(p))) {
            $createMask("icon-dingwei1", "账号或密码格式不对", 1500)
            return;
        }

        axios.post(BASE_URL + "/users/login", {
            "account": v,
            "password": p
        }).then(res => {

            if (res.data.status === 0 & res.data.msg === "OK") {
                
                localStorage.setExpire('data', JSON.stringify(res.data.data))
                $createMask("icon-dingwei", "操作成功", 2000, function () {
                     location.href = "./index.html"
                })

            } else {
                $createMask("icon-dingwei1", "账号或密码错误", 1500)
            }
        }).catch(r => {
            console.log(r);
            $createMask("icon-dingwei1", "网络错误", 1500)
        })

    })


})